﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// 文件名：ClsRemoveValidateDAL.cs
/// 作  者：Kidy
/// 时  间：2006.12.30
/// 说  明：ClsRemoveProduct类用于调拨出库、入库信息相关处理
public class ClsRemoveValidateDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    /// <summary>
    /// 获取所有产品调拔主表信息
    /// </summary>
    /// <param name="Co_ID">公司ID</param>
    /// <param name="User_ID">用户ID</param>
    /// <param name="Ds_ID">数据集ID</param>
    /// <returns>返回退货主表信息数据集</returns>
    public DataSet GetRemoveProductMains(string sCurUserId,string sType)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetRemoveOutDs", con);
        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        dat.SelectCommand.Parameters.Add("@u_log_id", sCurUserId);
        dat.SelectCommand.Parameters.Add("@Type", sType);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    /// <summary>
    /// 获取所有调拨出库确认从表信息
    /// <param name="Tm_On"></param>
    /// </summary>CREATE BY KIDY ON 20061230 
    /// <returns>返回退货从表信息数据集</returns>
    /// strTm_type, ctbRstm_no.Text.Trim()
    public DataSet GetRemoveProductChilds(string sType,string sTm_No)
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetRemoveList", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;
        dat.SelectCommand.Parameters.Add("@Type", sType);
        dat.SelectCommand.Parameters.Add("@Tm_no", sTm_No);

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }


    /// <summary>
    /// 增加 产品调拔 信息
    /// </summary>
    /// <param> 产品调拔 编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
/// strTm_no, dtTm_date, strIk_id, strdp_id, strWk_id,strWho_id, strWhi_id, strcr_id, strRemark
    public Boolean AddRemoveProduct(string sTm_no, DateTime dtTm_date, string sIk_id, string sdp_id, string sWk_id, string sWho_id,
                    string sWhi_id, string sCr_id,string sOper,string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pr_AddRemoveProductM", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Tm_no", SqlDbType.NVarChar, 20);
        com.Parameters["@Tm_no"].Value = sTm_no;
        com.Parameters.Add("@Tm_date", SqlDbType.DateTime, 8);
        com.Parameters["@Tm_date"].Value = dtTm_date;
        com.Parameters.Add("@Ik_id", SqlDbType.NVarChar, 40);
        com.Parameters["@Ik_id"].Value = sIk_id;
        com.Parameters.Add("@dp_id", SqlDbType.NVarChar, 40);
        com.Parameters["@dp_id"].Value = sdp_id;
        com.Parameters.Add("@Wk_id", SqlDbType.NVarChar, 40);
        com.Parameters["@Wk_id"].Value = sWk_id;
        com.Parameters.Add("@Who_id", SqlDbType.NVarChar, 40);
        com.Parameters["@Who_id"].Value = sWho_id;
        com.Parameters.Add("@Whi_id", SqlDbType.NVarChar, 40);
        com.Parameters["@Whi_id"].Value = sWhi_id;
        com.Parameters.Add("@Cr_id", SqlDbType.NVarChar, 40);
        com.Parameters["@Cr_id"].Value = sCr_id;
        com.Parameters.Add("@Oper", SqlDbType.NVarChar, 12);
        com.Parameters["@Oper"].Value = sOper;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;
  
        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加调拨出库确认信息
    /// </summary>
    /// <param> </param>
    /// <paramparam>
    /// <returns>返回修改是否成功</returns>
    /// strTm_type, strValiOut_no, dtValiOut_date, strOut_no,dtOut_date, strOper,strValier, strRemark
    public Boolean AddRemoveOutValidate(string sTm_type, string sValiOut_no, DateTime dValiOut_date, string sOut_no,DateTime dOut_date,
        string sOper, string sValier, string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddRemoveOutValidate", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 30);
        com.Parameters["@Type"].Value = sTm_type;
        com.Parameters.Add("@ValiOut_no", SqlDbType.NVarChar, 30);
        com.Parameters["@ValiOut_no"].Value = sValiOut_no;
        com.Parameters.Add("@ValiOut_date", SqlDbType.DateTime, 8);
        com.Parameters["@ValiOut_date"].Value = dValiOut_date;
        com.Parameters.Add("@Out_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Out_no"].Value = sOut_no;
        com.Parameters.Add("@Out_date", SqlDbType.DateTime, 8);
        com.Parameters["@Out_date"].Value = dOut_date;
        com.Parameters.Add("@Writer", SqlDbType.NVarChar, 20);
        com.Parameters["@Writer"].Value = sOper;
        com.Parameters.Add("@Valier", SqlDbType.NVarChar, 20);
        com.Parameters["@Valier"].Value = sValier;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加 产品调拔 明细信息
    /// </summary>
    /// <param> 产品调拔 编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    public Boolean AddChildRemoveProduct(string sTm_no, string sIm_id, int iChildAcount, decimal dChildPrice,
        string sBatchNo, string sIdentifyNo, string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddRemoveProductD", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Tm_no", SqlDbType.NVarChar, 20);
        com.Parameters["@Tm_no"].Value = sTm_no;
        com.Parameters.Add("@Im_id", SqlDbType.NVarChar, 20);
        com.Parameters["@Im_id"].Value = sIm_id;
        com.Parameters.Add("@ChildAcount", SqlDbType.Int, 4);
        com.Parameters["@ChildAcount"].Value = iChildAcount;
        com.Parameters.Add("@ChildPrice", SqlDbType.Decimal, 28);
        com.Parameters["@ChildPrice"].Value = dChildPrice;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = sBatchNo;
        com.Parameters.Add("@oo_no", SqlDbType.NVarChar, 30);
        com.Parameters["@oo_no"].Value = sIdentifyNo;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 删除 调拨出库确认主表 信息
    /// </summary>--CREATE BY KIDY ON 20061230
    /// <param name="Is_Visible">删除状态0为临时删除，1为彻底删除</param>
    /// <returns>返回删除是否成功</returns>
    public Boolean DeleteRemoveProduct(string sType,string sVali_no, int iIs_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteRemove", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 20);
        com.Parameters["@Type"].Value = sType;
        com.Parameters.Add("@Vali_no", SqlDbType.NVarChar, 20);
        com.Parameters["@Vali_no"].Value = sVali_no;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = iIs_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 删除 调拨出库 信息
    /// </summary>
    /// <param> 产品调拔 编号</param>
    /// <param name="Is_Visible">删除状态1为临时删除，－1为彻底删除</param>
    /// <returns>返回删除是否成功</returns>
    public Boolean DeleteChildRemoveProduct(string sType,string sVali_no, string sIm_no,string sLot_no,int iIs_Visible)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteRemValiChilds", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 30);
        com.Parameters["@Type"].Value = sType;
        com.Parameters.Add("@Vali_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Vali_no"].Value = sVali_no;
        com.Parameters.Add("@Im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Im_no"].Value = sIm_no;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = sLot_no;
        com.Parameters.Add("@Is_Visible", SqlDbType.Int, 1);
        com.Parameters["@Is_Visible"].Value = iIs_Visible;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 判断产品调拨是否可以确认：明细表有记录则可以确认，反之不可以确认
    /// </summary>
    /// <param name="Tm_No">单号</param>
    /// <param name="State"></param>
    /// <param name="Auditor">操作员</param>
    /// <returns>操作是否成功</returns>
    public string WhetherAuditRemoveProduct(string sTm_No)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_WhetherAuditRemoveProductM", con);
        com.CommandType = CommandType.StoredProcedure;

        //com.Parameters.Add("@tm_type", SqlDbType.NVarChar, 2);
        //com.Parameters["@tm_type"].Value = sTm_Type;
        com.Parameters.Add("@tm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@tm_no"].Value = sTm_No;

        try
        {
            con.Open();
            string strReturn = (string)com.ExecuteScalar();
            return strReturn;
        }
        catch
        {
            return null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    ///// <summary>
    ///// 确认 产品调拔 信息
    ///// </summary>
    ///// <param> 产品调拔 编号</param>
    ///// <param name="AuditStat">确认状态</param>
    ///// <param name="Auditor">确认人</param>
    ///// <returns>返回确认是否成功</returns>
    //public Boolean AuditStatRemoveProduct(string ID, int AuditStat, string Auditor)
    //{
    //    SqlConnection con = new SqlConnection(strSqlConnectionString);
    //    SqlCommand com = new SqlCommand("Pro_AudittbhTranM_Remove", con);//Pro_AuditStatRemoveProduct Pro_AudittbhTranM

    //    com.CommandType = CommandType.StoredProcedure;
    //    com.Parameters.Add("@tm_no", SqlDbType.NVarChar, 20);
    //    com.Parameters["@tm_no"].Value = ID;
    //    com.Parameters.Add("@dm_state", SqlDbType.Int);
    //    com.Parameters["@dm_state"].Value = AuditStat;
    //    com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
    //    com.Parameters["@auditor"].Value = Auditor;
    //    com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
    //    com.Parameters["@type"].Value = "08";

    //    try
    //    {
    //        con.Open();
    //        com.ExecuteNonQuery();

    //        return true;
    //    }
    //    catch
    //    {
    //        return false;
    //    }
    //    finally
    //    {
    //        if (con.State == ConnectionState.Open)
    //        {
    //            con.Close();
    //        }
    //    }
    //}

    /// <summary>
    /// 检查 移库单 是否可以确认：依据（库存中是否有相应记录，并且出库数量小于或等于该商品期末数量）
    /// <returns>CREATE BY KIDY ON 20061211</returns>
    /// </summary>
    public String CheckWhetherAudtitRemove(string sTm_No, string sTm_Type, int iState, string Auditor)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AudittbhTranM_RemoveStore", con); //Pro_AudittbhTranM_Remove
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = sTm_No;
        com.Parameters.Add("@dm_state", SqlDbType.Int, 4);
        com.Parameters["@dm_state"].Value = iState;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sTm_Type;
        ParOutPut = com.Parameters.Add("@reIm_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@relot_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@returnState", SqlDbType.NVarChar, 2);
        ParOutPut.Direction = ParameterDirection.Output;
        try
        {
            con.Open();
            com.ExecuteNonQuery();
            string strState = com.Parameters["@returnState"].Value.ToString();//返回状态（N:未入库;Q:库存不足）
            string strReIm_no = com.Parameters["@reIm_no"].Value.ToString();//返回的商品号
            string strReLot_no = com.Parameters["@relot_no"].Value.ToString();//返回的批号
            if (strState == "N")
            {
                return "N" + "|" + strReIm_no + "|" + strReLot_no;
            }
            else if (strState == "Q")
            {
                return "Q" + "|" + strReIm_no + "|" + strReLot_no;
            }
            else
            {
                return "0";
            };
        }
        catch
        {
            return "";
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改 调拨确认单号 信息
    /// </summary>
    /// <param> </param>
    /// <returns>返回修改是否成功</returns>
    ///strTm_type, ctsTm_No.Text,DateTime.Parse(ctsbRsVali_date.Text), Remark.Text
    public Boolean UpDateRemoveProduct(string sType,string sVali_no, DateTime dVali_date,string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateRemove", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 30);
        com.Parameters["@Type"].Value = sType;
        com.Parameters.Add("@Vali_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Vali_no"].Value = sVali_no;
        com.Parameters.Add("@Vali_date", SqlDbType.DateTime, 8);
        com.Parameters["@Vali_date"].Value = dVali_date;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 修改 调拨出库确认 明细信息
    /// </summary>CREATE BY KIDY ON 20061230
    /// <param> 产品调拔 编号</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
///strTm_type, strVali_No, txtChildRsIm_id.Text, decimal.Parse(ctbChildRsQty.Text),  Remark.Text
    public Boolean UpDateRemoveProductD(string sType,string sVali_no, string sIm_id,string sBatch_no, decimal dQty,string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpDateRemoveValidate", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 30);
        com.Parameters["@Type"].Value = sType;
        com.Parameters.Add("@Vali_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Vali_no"].Value = sVali_no;
        com.Parameters.Add("@Im_id", SqlDbType.NVarChar, 30);
        com.Parameters["@Im_id"].Value = sIm_id;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = sBatch_no;
        com.Parameters.Add("@Qty", SqlDbType.Decimal, 28);
        com.Parameters["@Qty"].Value = dQty;        
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;
       
        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 检查 调拨出库,调拨入库 是否可以确认：依据（库存中是否有相应记录，并且出库数量小于或等于该商品期末数量）
    /// <returns>CREATE BY KIDY ON 20061208</returns>
    /// </summary>
    public String CheckWhetherAudtit(string sTm_No, string sTm_Type, int iState, string Auditor)
    {

        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AudittbhTranM_RemoveTt", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@dm_no", SqlDbType.NVarChar, 30);
        com.Parameters["@dm_no"].Value = sTm_No;
        com.Parameters.Add("@dm_state", SqlDbType.Int, 4);
        com.Parameters["@dm_state"].Value = iState;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sTm_Type;
      
        try
        {
            con.Open();
            com.ExecuteNonQuery();           
                return "0";           
        }
        catch
        {
            return "1";
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 检查调拨出库确认单是否可以确认（商品出库数量不能>调拨出库商品剩余数量）
    /// </summary>CREATE BY KIDY ON 20061230
    /// <param name="sType"></param>
    /// <param name="sInto_no"></param>
    /// <returns></returns>
    public int ChkIsAudit(string sType, string sOut_no,string sIm_no,string slot_no)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_ChkIsAuditByRemoveValidate", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sType;
        com.Parameters.Add("@Out_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Out_no"].Value = sOut_no;
        com.Parameters.Add("@im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@im_no"].Value = sIm_no;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = slot_no;

        try
        {
            con.Open();
            int iReturn = int.Parse(com.ExecuteScalar().ToString());
            return iReturn;
        }
        catch
        {
            return 0;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

    }

    /// <summary>
    /// 检查调拨入库确认单明细中商品数量是否可以正确修改
    /// </summary>CREATE BY KIDY ON 20061231
    /// <param name="sType"></param>
    /// <param name="sInto_no"></param>
    /// <returns></returns>
    public int ChkReIntoIsUpdate(string sType, string sOutVali_no, string sIm_no, string sLot_no)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_ChkIsAuditByRemoveIntoValidate", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        //com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        //com.Parameters["@type"].Value = sType;
        com.Parameters.Add("@OutVali_no", SqlDbType.NVarChar, 30);
        com.Parameters["@OutVali_no"].Value = sOutVali_no;
        com.Parameters.Add("@im_no", SqlDbType.NVarChar, 30);
        com.Parameters["@im_no"].Value = sIm_no;
        com.Parameters.Add("@lot_no", SqlDbType.NVarChar, 30);
        com.Parameters["@lot_no"].Value = sLot_no;
        //ParOutPut = com.Parameters.Add("@reState", SqlDbType.Int);
        //ParOutPut.Direction = ParameterDirection.Output;

        try
        {
            con.Open();
            int iSpare_qty = int.Parse(com.ExecuteScalar().ToString());
            return iSpare_qty;
            //string strReState = com.Parameters["@reState"].Value.ToString();//返回状态（0:成功;1:失败）
            //return strReState;
        }
        catch
        {
            return 0;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

    }

    /// <summary>
    /// 检查 调拨出库,调拨入库 是否可以确认：依据（库存中是否有相应记录，并且出库数量小于或等于该商品期末数量）
    /// <returns>CREATE BY KIDY ON 20061231</returns>
    /// </summary>
    public String CheckRemoveWhetherAudit(string sTm_No, string sTm_Type, int iState, string Auditor)
    {

        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AuditRemoveProduct", con);
        com.CommandType = CommandType.StoredProcedure;
        SqlParameter ParOutPut = new SqlParameter();

        com.Parameters.Add("@vali_no", SqlDbType.NVarChar, 30);
        com.Parameters["@vali_no"].Value = sTm_No;
        com.Parameters.Add("@dm_state", SqlDbType.Int, 4);
        com.Parameters["@dm_state"].Value = iState;
        com.Parameters.Add("@auditor", SqlDbType.NVarChar, 60);
        com.Parameters["@auditor"].Value = Auditor;
        com.Parameters.Add("@type", SqlDbType.NVarChar, 2);
        com.Parameters["@type"].Value = sTm_Type;
        ParOutPut = com.Parameters.Add("@reIm_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@relot_no", SqlDbType.NVarChar, 30);
        ParOutPut.Direction = ParameterDirection.Output;
        ParOutPut = com.Parameters.Add("@returnState", SqlDbType.NVarChar, 2);
        ParOutPut.Direction = ParameterDirection.Output;
        try
        {
            con.Open();
            com.ExecuteNonQuery();
            string strState = com.Parameters["@returnState"].Value.ToString();//返回状态（N:未入库;Q:库存不足）
            string strReIm_no = com.Parameters["@reIm_no"].Value.ToString();//返回的商品号
            string strReLot_no = com.Parameters["@relot_no"].Value.ToString();//返回的批号
            if (strState == "N")
            {
                return "N" + "|" + strReIm_no + "|" + strReLot_no;
            }
            else if (strState == "Q")
            {
                return "Q" + "|" + strReIm_no + "|" + strReLot_no;
            }
            else
            {
                return "0";
            }
        }
        catch
        {
            return "";
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 增加调拨入库信息
    /// </summary>
    /// <param> CREATE BY KIDY ON 20061231</param>
    /// <param>......</param>
    /// <returns>返回修改是否成功</returns>
    /// strTm_type, strValiOut_no, dtValiOut_date, strOut_no,dtOut_date, strOper,strValier, strRemark
    public Boolean AddRemoveIntoValidate(string sTm_type, string sInto_no, DateTime dInto_date, string sOut_no, DateTime dOut_date,
        string sOper, string sValier, string sRemark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddRemoveIntoFromRemoveOut", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@Type", SqlDbType.NVarChar, 30);
        com.Parameters["@Type"].Value = sTm_type;
        com.Parameters.Add("@Into_no", SqlDbType.NVarChar, 30);
        com.Parameters["@Into_no"].Value = sInto_no;
        com.Parameters.Add("@Into_date", SqlDbType.DateTime, 8);
        com.Parameters["@Into_date"].Value = dInto_date;
        com.Parameters.Add("@ValiOut_no", SqlDbType.NVarChar, 30);
        com.Parameters["@ValiOut_no"].Value = sOut_no;
        com.Parameters.Add("@ValiOut_date", SqlDbType.DateTime, 8);
        com.Parameters["@ValiOut_date"].Value = dOut_date;
        com.Parameters.Add("@Writer", SqlDbType.NVarChar, 20);
        com.Parameters["@Writer"].Value = sOper;
        com.Parameters.Add("@Valier", SqlDbType.NVarChar, 20);
        com.Parameters["@Valier"].Value = sValier;
        com.Parameters.Add("@Remark", SqlDbType.NVarChar, 255);
        com.Parameters["@Remark"].Value = sRemark;

        try
        {
            con.Open();
            com.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    /// <summary>
    /// 检查调拨出库确认单确认后是否可以取消确认核
    /// </summary>CREATE BY KIDY ON 20070123
    /// <param name="sType"></param>
    /// <param name="sBod_no"></param>
    /// <returns></returns>
    public bool ChkNoAuditRemOutValidate(string sBod_no)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_ChkNoAuditRemOutVali", con);
        com.CommandType = CommandType.StoredProcedure;

        com.Parameters.Add("@bod_no", SqlDbType.NVarChar, 30);
        com.Parameters["@bod_no"].Value = sBod_no;  

        try
        {
            con.Open();
            bool bAudit = bool.Parse(com.ExecuteScalar().ToString());
            return bAudit;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

}

